#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;
const int MOD = 998244353;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int a[N];
int b[N], num;
void discrete() {
  rep(i, 1, n) b[i] = a[i];
  sort(b + 1, b + n + 1);
  num = unique(b + 1, b + n + 1) - b - 1;
  rep(i, 1, n) a[i] = lower_bound(b + 1, b + num + 1, a[i]) - b;
}
ll sum[N << 2], tag[N << 2];
void build(int p, int l, int r) {
  sum[p] = 0, tag[p] = 1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
}
void addtag(ll k, int p) {
  sum[p] = sum[p] * k % MOD;
  tag[p] = tag[p] * k % MOD;
}
void pushdown(int p) {
  if (tag[p] != 1) {
    addtag(tag[p], p << 1);
    addtag(tag[p], p << 1 | 1);
    tag[p] = 1;
  }
}
void pushup(int p) { sum[p] = (sum[p << 1] + sum[p << 1 | 1]) % MOD; }
void update2(int L, int R, ll k, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(k, p);
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (L <= mid) update2(L, R, k, p << 1, l, mid);
  if (R > mid) update2(L, R, k, p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int x, ll d, int p, int l, int r) {
  if (l == r) {
    sum[p] = (sum[p] + d) % MOD;
    return;
  }
  pushdown(p);
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, d, p << 1, l, mid);
  else
    update(x, d, p << 1 | 1, mid + 1, r);
  pushup(p);
}
ll query(int x, int p, int l, int r) {
  if (l == r) return sum[p];
  pushdown(p);
  int mid = (l + r) >> 1;
  if (x <= mid)
    return query(x, p << 1, l, mid);
  else
    return query(x, p << 1 | 1, mid + 1, r);
}
int st[N], top;
ll c[N], d[N];
ll ans;
void solve() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  discrete();

  top = 0;
  rep(i, 1, n) if (!top || st[top] < a[i]) st[++top] = a[i];
  build(1, 0, num);
  update(0, 1, 1, 0, num);
  rep(i, 1, n) {
    if (a[i] == st[top]) {
      c[i] = (query(st[top - 1], 1, 0, num) + query(st[top], 1, 0, num)) % MOD;
    }
    update2(a[i], num, 2, 1, 0, num);
    int id = lower_bound(st + 1, st + top + 1, a[i]) - st;
    if (id <= top && st[id] == a[i]) {
      int pre = st[id - 1];
      ll x = query(pre, 1, 0, num);
      update(a[i], x, 1, 0, num);
    }
  }

  top = 0;
  per(i, n, 1) if (!top || st[top] < a[i]) st[++top] = a[i];
  build(1, 0, num);
  update(0, 1, 1, 0, num);
  per(i, n, 1) {
    update2(a[i], num, 2, 1, 0, num);
    int id = lower_bound(st + 1, st + top + 1, a[i]) - st;
    if (id <= top && st[id] == a[i]) {
      int pre = st[id - 1];
      ll x = query(pre, 1, 0, num);
      update(a[i], x, 1, 0, num);
      if (id == top) d[i] = x;
    }
  }
  ll ans = 0;
  rep(i, 1, n) if (a[i] == st[top]) ans = (ans + c[i] * d[i]) % MOD;
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}